<?php

namespace app\api\controller;

use app\api\model\house\HouseMedia;
use app\common\controller\Api;
use app\api\model\house\House as HouseModel;
use app\api\model\house\HouseEvaluate as HouseEvaluateModel;

class House extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];

    //房屋首页的点赞/转发/评论/收藏数
    public function data()
    {
        $zan_num = HouseModel::sum('zan_num');
        $collect_num = HouseModel::sum('collect_num');
        $repost_num = HouseModel::sum('repost_num');
        $comment_num = HouseEvaluateModel::count();

        $data = [
            'zan_num'=>$zan_num,
            'collect_num'=>$collect_num,
            'repost_num'=>$repost_num,
            'comment_num'=>$comment_num
        ];

        $this->success('',$data);
    }

    //增加房屋的转发次数
    public function addrepost()
    {
        $house_id = input('house_id',0);
        HouseModel::where(['house_id'=>$house_id])->setInc('repost_num',1);
        $this->success('');
    }

    //推荐订房
    public function recommend()
    {
        $model = new HouseModel();
        $param = input();
        $list = $model->recommend($param);
        $this->success('',$list);
    }

    //订房首页
    public function index()
    {
        $model = new HouseModel();
        $param = input();
        $list = $model->index($param);
        $this->success('',$list);
    }

    //订房列表
    public function lists()
    {
        $model = new HouseModel();
        $param = input();
        $list = $model->lists($param);
        $this->success('',$list);
    }



    //房屋详情
    public function info()
    {
        try {
            $model = new HouseModel();
            $param = input();
            $info = $model->info($param);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }

        $this->success('',$info);
    }


    //根据入住日期和离开日期查询整屋房屋是否可住
    public function canCheckin()
    {
        try {
            $model = new HouseModel();
            $data = [
                'house_id'=>input('house_id',0),
                'checkin_date'=>input('checkin_date',''),
                'leave_date'=>input('leave_date',''),
            ];
            $info = $model->canCheckin($data);

        } catch (\Exception $e) {
            $this->error($e->getMessage());
        }
        $this->success('',$info);
    }

    //根据入住日期和离开日期查询房屋拼房状态
    public function pinfangStatus()
    {
        $model = new HouseModel();
        $data = [
            'house_id'=>input('house_id',0),
            'checkin_date'=>input('checkin_date',''),
            'leave_date'=>input('leave_date',''),
        ];
        $info = $model->pinfangStatus($data);

        $this->success('',$info);
    }


}